package io.mybatis.example.springboot.controller;

import io.mybatis.common.core.DataResponse;
import io.mybatis.common.core.RowsResponse;

import io.mybatis.example.springboot.model.SysJobLog;
import io.mybatis.example.springboot.service.SysJobLogService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * sys_job_log - 定时任务调度日志表
 *
 * @author mkj
 */
@RestController
@RequestMapping("sysJobLogs")
public class SysJobLogController {

  @Autowired
  private SysJobLogService sysJobLogService;

  @PostMapping
  public DataResponse<SysJobLogDO> save(@RequestBody SysJobLogDO sysJobLog) {
    return DataResponse.ok(sysJobLogService.save( sysJobLog));
  }

  @GetMapping
  public RowsResponse<SysJobLogDO> findList(@RequestBody SysJobLogDO sysJobLog) {
    return RowsResponse.ok(sysJobLogService.findList( sysJobLog));
  }

  @GetMapping(value = "/{id}")
  public DataResponse<SysJobLogDO> findById(@PathVariable("id") Long id) {
    return DataResponse.ok(sysJobLogService.findById(id));
  }

  @PutMapping(value = "/{id}")
  public DataResponse<SysJobLogDO> update(@PathVariable("id") Long id, @RequestBody SysJobLogDO sysJobLog) {
    sysJobLog.setId(id);
    return DataResponse.ok(sysJobLogService.update( sysJobLog));
  }

  @DeleteMapping(value = "/{id}")
  public DataResponse<Boolean> deleteById(@PathVariable("id") Long id) {
    return DataResponse.ok(sysJobLogService.deleteById(id) == 1);
  }

}
